package com.example.demo1115.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo1115.dao.BookOneDao;
import com.example.demo1115.entity.Book;
import com.example.demo1115.service.BookOneService;
import com.example.demo1115.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BookOneServiceImpl implements BookOneService {
    @Autowired
    private BookOneDao bookOneDao;

    @Override
    public Result findAll(Integer current, Integer pageSize) {
        Page<Book> page=new Page<>(current,pageSize);
        Page<Book> page1 = bookOneDao.selectPage(page, null);
        return new Result(200,"查询成功",page1);
    }

    @Override
    public Result insertone(String isbn, String bookName, int price) {
        Book user=new Book(isbn,bookName,price);
        int insert = bookOneDao.insert(user);
        return new Result(200,"插入成功",insert);
    }

    @Override
    public Result updateone(String isbn, String bookName, int price) {
        Book book=new Book();
        book.setBookName(bookName);
        book.setPrice(price);
        UpdateWrapper<Book> wrapper=new UpdateWrapper<>();
        wrapper.eq("isbn",isbn);
        int update = bookOneDao.update(book, wrapper);
        return new Result(200,"更新成功",update);
    }

    @Override
    public Result deleteByisbn(String isbn) {
        LambdaUpdateWrapper<Book> wrapper=new LambdaUpdateWrapper<>();
        wrapper.eq(Book::getIsbn,isbn);
        int delete = bookOneDao.delete(wrapper);
        return new Result(200,"删除成功",delete);
    }
}
